package com.example.sls.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.example.sls.service.intserfaces.user.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 编者：蓝江富
 * 时间：2024/6/16 16:05
 */
@RestController
@SaIgnore// 不拦截此接口
@RequestMapping("test")
public class TestController {
  @Autowired
  UsersService usersService;
  // 测试登录  ---- http://localhost:8081/acc/doLogin?name=zhang&pwd=123456
  @RequestMapping("doLogin")
  public SaResult doLogin(String name, String pwd) {
    StpUtil.login(usersService.findByUsersName(name).getId());
    return SaResult.ok("登录成功");
  }

  // 查询登录状态  ---- http://localhost:8081/acc/isLogin
  @RequestMapping("isLogin")
  public SaResult isLogin() {
    return SaResult.ok("是否登录：" + StpUtil.isLogin());
  }

  // 查询 Token 信息  ---- http://localhost:8081/acc/tokenInfo
  @RequestMapping("tokeninfo")
  public SaResult tokenInfo() {
    return SaResult.data(StpUtil.getTokenInfo());
  }
  @RequestMapping("showPermission")
  public SaResult showPermission(){
    return SaResult.data(StpUtil.getPermissionList());
  }
  @RequestMapping("showRole")
  public SaResult showRole(){
    return SaResult.data(StpUtil.getRoleList());
  }

  // 测试注销  ---- http://localhost:8081/acc/logout
  @RequestMapping("logout")
  public SaResult logout() {
    StpUtil.logout();
    return SaResult.ok();
  }
}
